<template>
  <div class="transaction-cases">
    <!-- 标题区域 -->
    <div class="section-header">
      <div class="title-section">
        <h2 class="main-title">成交案例</h2>
        <span class="sub-title">transaction case</span>
      </div>
    </div>

    <!-- 案例卡片区域 -->
    <div class="cases-container">
      <el-row :gutter="20" class="custom-row">
        <el-col 
          v-for="(item, index) in caseList.slice(0,8)" 
          :key="index" 
          :xs="24" 
          :sm="12" 
          :md="12" 
          :lg="6"
          @click="handleContainerClick(item)"
        >
          <el-card class="case-card" shadow="hover">
          
            
            <!-- 图片区域 -->
            <div class="case-image">
              <el-image
                :src="item.imageUrl"
                :alt="item.equipmentId"
                fit="cover"
                class="image"
                @error="handleImageError(index)"
              >
                <template #error>
                  <div class="image-error">
                    <el-icon></el-icon>
                    <span>加载失败</span>
                  </div>
                </template>
              </el-image>
            </div>

            <!-- 内容区域 -->
            <div class="case-content">
              <h3 class="case-title">[成功案例]{{ item.title }}</h3>
              <h3 class="case-title">{{ item.year }}年{{ item.brand}}牌{{ item.typeName }}型号{{ item.model }}</h3>
              <p class="update-time">{{ item.createTime }}更新</p>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script setup>
import { onMounted, ref } from 'vue'
import { Document,  } from '@element-plus/icons-vue'
import axios from 'axios'
import { useRouter,useRoute } from 'vue-router'

const router = useRouter()
const route = useRoute()

const caseList=ref([])

const getCaseData = async () => {
  try {
    
    const res = await axios.get('advertisement/addOrder')

    caseList.value = res.data.data.list
  } catch (error) {
    console.error("获取案例数据失败:", error)
  }
}
// 图片加载失败处理
const handleImageError = (index) => {
  console.log(`图片 ${index} 加载失败`)
}

const handleContainerClick = (ref) => {
 // 跳转到详情页面
 router.push({
    name: 'xiangqing',
    params: {
      id: ref.orderId
    }

  });
};




onMounted(() => {
  getCaseData()
})
</script>

<style scoped>
.transaction-cases {
  max-width: 100%;
  margin: 0 auto;
  padding: 40px 20px;
}

/* 标题区域样式 */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 30px;
  border-bottom: 2px solid #409EFF;
  padding-bottom: 10px;
}

.title-section {
  display: flex;
  align-items: baseline;
  gap: 15px;
}

.main-title {
  font-size: 24px;
  font-weight: 600;
  color: #333;
  margin: 0;
}

.sub-title {
  font-size: 14px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.view-more {
  font-size: 14px;
  color: #409EFF;
}

/* 卡片容器样式 */
.cases-container {
  margin-top: 20px;
}

.case-card {
  height: 100%;
  transition: all 0.3s ease;
  border: 1px solid #f0f0f0;
}

.case-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* 图标样式 */
.case-icon {
  display: flex;
  justify-content: center;
  margin-bottom: 15px;
  padding: 10px;
  background: #f5f7fa;
  border-radius: 6px;
}

/* 图片区域样式 */
.case-image {
  width: 100%;
  height: 180px;
  margin-bottom: 15px;
  border-radius: 6px;
  overflow: hidden;
}

.image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-error {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: #f5f5f5;
  color: #999;
}

.image-error .el-icon {
  font-size: 40px;
  margin-bottom: 10px;
}

/* 内容区域样式 */
.case-content {
  text-align: center;
}

.case-title {
  font-size: 16px;
  font-weight: 500;
  color: #333;
  margin: 0 0 10px 0;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.update-time {
  font-size: 12px;
  color: #999;
  margin: 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  
  .title-section {
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
  }
  
  .case-image {
    height: 150px;
  }
}
.custom-row {
  margin-bottom: -20px; /* 抵消最后一个元素的 margin-bottom */
}

.custom-row .el-col {
  margin-bottom: 20px; /* 设置行间距 */
}
</style>